home *** CD-ROM | disk | FTP | other *** search
- #include "sprite.h"
- #include "status.h"
- #include "stdio.h"
- #include "sysStats.h"
- #include "spriteTime.h"
- #include "host.h"
- #include "option.h"
-
- int numStats = 100; /* A good number to try first. */
-
- /*
- * For per-client statistics about recovery on the server. This amounts to
- * a per-host list, in array form, where the first element in each list is the
- * Sys_RecovPerHostFirstInfo, and all the following items are time-stamps,
- * but they are defined as a union since both types of elements must be the
- * same size when copied out to the user (here). Each host has a
- * Sys_RecovPerHostFirstInfo, followed by (numTries - 1) time-stamps.
- */
- typedef struct Sys_RecovPerHostInfo {
- int spriteID; /* Sprite ID of client. */
- Time start; /* First recovery attempt. */
- Time finished; /* First recovery attempt finished. */
- int numTries; /* Number of recovery attempts. */
- int numHandles; /* Number of reopens requested. */
- int numSuccessful; /* Handles successfully recovered. */
- } Sys_RecovPerHostInfo;
-
- /*
- * Option declarations.
- */
- Boolean duration = FALSE;
- Boolean noHandles = FALSE;
- Boolean success = FALSE;
- Option optionArray[] = {
- {OPT_TRUE, "noHandles", (char *) &noHandles,
- "Don't include handle reopen counts."},
- {OPT_TRUE, "success", (char *) &success,
- "Show count of successful reopens."},
- {OPT_TRUE, "duration", (char *) &duration,
- "Only show duration of recovery per host."}
- };
-
- int numOptions = sizeof (optionArray) / sizeof (Option);
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- ReturnStatus status;
- int bufSize;
- Sys_RecovPerHostInfo *infoPtr;
- Sys_RecovPerHostInfo *stats;
- Sys_RecovPerHostInfo *lastInfoPtr;
- int i;
- char firstTimeBuf[26];
- char finishedTimeBuf[26];
- int myID;
- Host_Entry *hostInfoPtr;
- int numClients = 0;
- int avgNumTries = 0;
- int lowTime = 0;
- int highTime = 0;
- struct tm *tp;
- int numTries;
- int totalReopenRequests = 0;
- int totalHandlesReallyReopened = 0;
- int totalSuccessfulRequests = 0;
- int totalSuccessfulReallyReopened = 0;
-
- /*
- * Should I wait for 5 minutes, till recovery is probably done, then try
- * to dump
- * recovery statistics and then clear them? If recovery is still going
- * on, we'll get a failure status and loop around again.
- */
-
- /*
- * Parse arguments.
- */
- Opt_Parse(argc, argv, optionArray, numOptions, 0);
- if (success && noHandles) {
- printf("Options 'success' and 'noHandles' are contradictory.\n");
- exit(1);
- }
-
- bufSize = numStats * sizeof (Sys_RecovPerHostInfo);
- stats = (Sys_RecovPerHostInfo *) malloc(bufSize);
- status = Sys_Stats(SYS_RECOV_CLIENT_INFO, &bufSize, stats);
-
- /*
- * Did we need more space?
- */
- while (status == SUCCESS && (bufSize >
- numStats * sizeof (Sys_RecovPerHostInfo))) {
- numStats = bufSize / sizeof (Sys_RecovPerHostInfo);
-
- if (stats != (Sys_RecovPerHostInfo *) NULL) {
- free(stats);
- }
- stats = (Sys_RecovPerHostInfo *) malloc(bufSize);
- status = Sys_Stats(SYS_RECOV_CLIENT_INFO, &bufSize, stats);
- }
-
- if (status != SUCCESS) {
- printf("Stat call failed, status = 0x%x\n", status);
- exit(1);
- }
- system("echo Recovery info for server `hostname` `date`");
- printf("\n");
- if (noHandles) {
- printf("Host\t\tNumTries\tStarting\t\tFinished\n");
- } else if (success) {
- printf("Host\t\tNumTries\tStarting\t\tFinished\tHandles Successful\n");
- } else {
- printf("Host\t\tNumTries\tStarting\t\tFinished\tHandles\n");
- }
- numStats = bufSize / sizeof (Sys_RecovPerHostInfo);
- infoPtr = stats;
- for (i = 0; i < numStats; i++) {
- char *name;
- int j;
-
- if (infoPtr->numTries == 0) {
- infoPtr++;
- continue;
- }
- numClients++;
- avgNumTries += infoPtr->numTries; /* divided out later */
- lastInfoPtr = &stats[i + infoPtr->numTries - 1];
- totalReopenRequests += lastInfoPtr->numHandles;
- totalSuccessfulRequests += lastInfoPtr->numSuccessful;
- totalHandlesReallyReopened += lastInfoPtr->numHandles;
- totalSuccessfulReallyReopened += lastInfoPtr->numSuccessful;
- if (lowTime == 0) {
- lowTime = infoPtr->start.seconds;
- } else if (infoPtr->start.seconds < lowTime) {
- lowTime = infoPtr->start.seconds;
- }
- if (lastInfoPtr->finished.seconds > highTime) {
- highTime = lastInfoPtr->finished.seconds;
- }
- hostInfoPtr = Host_ByID(infoPtr->spriteID);
- Host_End();
- if (hostInfoPtr == NULL) {
- name = "unknown";
- } else if (hostInfoPtr->aliases != NULL &&
- hostInfoPtr->aliases[0] != NULL) {
- name = hostInfoPtr->aliases[0];
- } else {
- name = hostInfoPtr->name;
- }
- tp = (struct tm *) localtime(
- (time_t *) &(infoPtr->start.seconds));
- strcpy(firstTimeBuf, asctime(tp));
- tp = (struct tm *) localtime(
- (time_t *) &(lastInfoPtr->finished.seconds));
- strcpy(finishedTimeBuf, asctime(tp));
- /* get rid of newline */
- firstTimeBuf[24] = '\0';
- finishedTimeBuf[24] = '\0';
- if (noHandles) {
- if (strlen(name) >= 8) {
- printf("%s\t%d\t%s\t%s\n", name,
- infoPtr->numTries, firstTimeBuf, finishedTimeBuf);
- } else {
- printf("%s\t\t%d\t%s\t%s\n", name,
- infoPtr->numTries, firstTimeBuf, finishedTimeBuf);
- }
- } else if (success) {
- if (strlen(name) >= 8) {
- printf("%s\t%d\t%s %s %d %d\n", name,
- infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
- lastInfoPtr->numHandles,
- lastInfoPtr->numSuccessful);
- } else {
- printf("%s\t\t%d\t%s %s %d %d\n", name,
- infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
- lastInfoPtr->numHandles,
- lastInfoPtr->numSuccessful);
- }
- } else {
- if (strlen(name) >= 8) {
- printf("%s\t%d\t%s %s %d\n", name,
- infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
- lastInfoPtr->numHandles);
- } else {
- printf("%s\t\t%d\t%s %s %d\n", name,
- infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
- lastInfoPtr->numHandles);
- }
- }
- if (duration || infoPtr->numTries <= 1) {
- infoPtr++;
- continue;
- }
- numTries = infoPtr->numTries;
- /*
- * Process an additional time-stamp for each numTries over 1.
- */
- for (j = 0; j < numTries; j++) {
- tp = (struct tm *) localtime((time_t *)
- &(infoPtr->start.seconds));
- strcpy(firstTimeBuf, asctime(tp));
- tp = (struct tm *) localtime((time_t *)
- &(infoPtr->finished.seconds));
- strcpy(finishedTimeBuf, asctime(tp));
- if (j < numTries - 1) { /* last one already included */
- totalReopenRequests += infoPtr->numHandles;
- totalSuccessfulRequests += infoPtr->numSuccessful;
- }
- if (noHandles) {
- /* Remove newline from firstTime */
- firstTimeBuf[24] = '\0';
- printf("\t\t\t%s %s", firstTimeBuf, finishedTimeBuf);
- } else if (success) {
- /* Remove newlines */
- firstTimeBuf[24] = '\0';
- finishedTimeBuf[24] = '\0';
- printf("\t\t\t%s %s %d %d\n", firstTimeBuf, finishedTimeBuf,
- infoPtr->numHandles, infoPtr->numSuccessful);
- } else {
- /* Remove newlines */
- firstTimeBuf[24] = '\0';
- finishedTimeBuf[24] = '\0';
- printf("\t\t\t%s %s %d\n", firstTimeBuf, finishedTimeBuf,
- infoPtr->numHandles);
- }
- infoPtr++;
- }
- i += (numTries - 1);
- }
- highTime = highTime - lowTime;
- Time_ToAscii(highTime, TRUE, firstTimeBuf);
- if (noHandles) {
- printf(
- "\nNum Clients: %d, Avg Num Tries: %d, Total Time: %s hr:min:sec\n",
- numClients, numClients == 0 ? 0 : (avgNumTries / numClients), firstTimeBuf);
- } else if (success) {
- printf(
- "\nNum Clients: %d, Avg Num Tries: %d\nTotal Reopen Requests: %d, Total Handles Really Reopened: %d\nTotal Successful Requests: %d, Total Successful Really Reopened: %d\nTotal Time: %s hr:min:sec\n",
- numClients, numClients == 0 ? 0 : (avgNumTries / numClients), totalReopenRequests, totalHandlesReallyReopened, totalSuccessfulRequests, totalSuccessfulReallyReopened,
- firstTimeBuf);
- } else {
- printf(
- "\nNum Clients: %d, Avg Num Tries: %d\nTotal Reopen Requests: %d, Total Handles Really Reopened: %d\nTotal Time: %s hr:min:sec\n",
- numClients, numClients == 0 ? 0 : (avgNumTries / numClients), totalReopenRequests, totalHandlesReallyReopened, firstTimeBuf);
- }
-
- exit(0);
- }
-